package com.heyqing.topic.FirstUniqChar_0387;

/**
 * ClassName:FirstUniqChar
 * Package:com.heyqing.topic.FirstUniqChar_0387
 * Description:
 *
 * @Date:2024/9/28
 * @Author:Heyqing
 */
public class FirstUniqChar {
    public int firstUniqChar(String s) {
        int[] flag = new int[26];
        for (int i = 0; i < s.length(); i++) {
            flag[s.charAt(i) - 97]++;
        }
        for (int i = 0; i < s.length(); i++) {
            if (flag[s.charAt(i) - 97] == 1) return i;
        }
        return -1;
    }
}
